﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SD.Business;
using SD.DataAccess;

namespace SD.Web.Iteration1.Programme
{
    public partial class AddProgramme : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        /// <summary>
        /// Button Save Click event
        /// </summary>
        protected void ButtonSave_Click(object sender, EventArgs e)
        {
            if (TextBoxName.Text.Trim() == "")
            {
                lblCheck.Text = "Invalid name!";
                lblCheck.Visible = true;
                lblCheckSuccess.Visible = false;
                return;
            }
            ProgramBUS programBus = new ProgramBUS();
            SD.DataAccess.Program pro = new SD.DataAccess.Program();
            pro.IsActive = true;
            pro.ProgramName = TextBoxName.Text;                      
            pro.Description = TextBoxDescription.Text;
            if (!string.IsNullOrEmpty(HiddenFieldManagerId.Value))
            {
                pro.ContactId = Convert.ToInt16(HiddenFieldManagerId.Value);
            }
            //check name has already exist ?
            if (programBus.CheckNameProgram(pro.ProgramName) == true)
            {
                lblCheck.Text = "Program name has already existed!";
                lblCheck.Visible = true;
                lblCheckSuccess.Visible = false;
            }
            else
            {
                //check add program
                bool success = programBus.AddProgram(pro);
                if (success == true)
                {
                    lblCheck.Visible = false;
                    lblCheckSuccess.Visible = true;
                }
            }
        }

        /// <summary>
        /// Button Lookup Click event
        /// </summary>
        protected void ButtonLookup_Click(object sender, EventArgs e)
        {
            this.ContactLookup1.Popup();
        }

        /// <summary>
        /// Button Back Click event
        /// </summary>
        protected void ButtonBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("ProgramList.aspx");
        }

    }
}